﻿///
///   Copyright 2012 Grey Pocket
///
///   Licensed under the MIT License, Version 2.0 (the "License");
///   you may not use this file except in compliance with the License.
///   You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
///   Unless required by applicable law or agreed to in writing, software
///   distributed under the License is distributed on an "AS IS" BASIS,
///   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
///   See the License for the specific language governing permissions and
///   limitations under the License
///
using System;
using System.Collections.Generic;
using System.Windows.Forms;

using StreakyDownloader.Model;
using StreakyDownloader.View;

using log4net;
using log4net.Config;

namespace StreakyDownloader
{
   static class program
   {
      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
         // configure log4net from the app.config file.
         log4net.Config.XmlConfigurator.Configure();

         ILog logger = LogManager.GetLogger(typeof(program));
         logger.Info("..:: Starting StreakyDownloader " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + "::..");

         StreakyDownloadConfig config = new StreakyDownloadConfig();

         // get the list of files to download from the data file.
         DownloadQueue dlQueue = new DownloadQueue();
         dlQueue.ReadIds(config.DownloadIDDataFile);

         // create the object to manage downloading a file and reporting
         // the current status.
         FileDownloader downloader = new FileDownloader(config.BaseDLFile, 
                                                        config.BaseUIFile, 
                                                        config.OpenUIPage, 
                                                        new StreakyWebClient());
         
         // create the seperate thread to download each of the files and kick it off.
         DownloaderThread downloadThread = new DownloaderThread(dlQueue, downloader);
         downloadThread.DownloadFiles();

         frmDownloadProgress dlProgress = new frmDownloadProgress(downloader);

         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Application.Run(dlProgress);
      }
   }
}
